﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using InformationSystem.BLL.Core.Service;
using InformationSystem.BLL.Core.Model;
using Ext.Net;
using System.IO;

namespace InformationSystem.WebSite.Module.MailMgr
{
    public partial class MailOut : BasePage
    {
        public IInformationService InformationService { get; set; }
        protected LoginUser user;
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (LoginUser)Session["LoginUser"];
            IList<Mail> maillist = InformationService.GetMailSendList(user.UserID);
            mailStore.DataSource = maillist;
            mailStore.DataBind();
        }

        protected void BeforeRecordDeleted(object sender, BeforeRecordDeletedEventArgs e)
        {            
            Mail mail = e.Object<Mail>();            
            string path = Path.Combine(Server.MapPath("~"), Common.MailAttachmentPath);
            bool result = this.InformationService.DeleteMailSent(mail.MailID, user.UserID, path);
            X.Msg.Show(new MessageBoxConfig
            {
                Buttons = MessageBox.Button.OK,
                Icon = MessageBox.Icon.INFO,
                Title = "信息",
                Message = "删除成功！"
            });
        }
        protected void AfterStoreChanged(object sender, AfterStoreChangedEventArgs e)
        {
            IList<Mail> maillist = InformationService.GetMailSendList(user.UserID);
            mailStore.DataSource = maillist;
            mailStore.DataBind();
            this.mailStore.RefreshAfterSaving = RefreshAfterSavingMode.Always;
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            IList<Mail> maillist = InformationService.GetMailSendList(user.UserID);
            mailStore.DataSource = maillist;
            mailStore.DataBind();
        }

        protected override bool CommitPermissionCheck()
        {
            throw new NotImplementedException();
        }
    }
}